package com.tracesystem.controller;


import com.tracesystem.commons.Result;
import com.tracesystem.controller.form.*;
import com.tracesystem.controller.info.*;
import com.tracesystem.service.IssueBaseInfoService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  缺陷记录处理接口
 * </p>
 *
 * @author Kevin Martin
 * @since 2022-03-24
 */
@Api(tags = "缺陷记录处理接口")
@RestController
@RequestMapping("/issueBaseInfo")
public class IssueBaseInfoController {
    @Autowired
    private IssueBaseInfoService issueBaseInfoService;
    /*
     * @Description:新增缺陷
     * @Author: JMOCOK
     * @param issueForm: 缺陷参数
     * @return: com.tracesystem.commons.Result 统一返回
     **/
    @ApiOperation("新增缺陷记录")
    @PostMapping("/createIssue")
    public Result createIssue(@RequestBody @Valid IssueForm issueForm){
        return issueBaseInfoService.AddIssue(issueForm);
    }
    /*
     * @Description:修改缺陷记录
     * @Author: JMOCOK
     * @param modifyIssueForm: 缺陷更新参数
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("修改缺陷记录")
    @PostMapping("/change")
    public Result change(@RequestBody ModifyIssueForm modifyIssueForm){
        return issueBaseInfoService.modifyIssueInfo(modifyIssueForm);
    }

    /*
     * @Description:删除缺陷记录
     * @Author: JMOCOK
     * @param IssueId: 缺陷id
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("删除缺陷记录")
    @GetMapping("/deletion")
    public Result deletion(Integer issueId){
        return issueBaseInfoService.removeIssue(issueId);
    }
    /*
     * @Description:查询缺陷详情
     * @Author: JMOCOK
     * @param IssueId: 缺陷id
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("查询缺陷详情")
    @GetMapping("/issueDetail")
    public Result<IssueDetailInfo> getIssueDetail(Integer issueId){
        return  issueBaseInfoService.getIssueDetailById(issueId);
    }

    /*
     * @Description:查询缺陷记录
     * @Author: JMOCOK
     * @param IssueId: 缺陷id
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("查询缺陷记录")
    @GetMapping("/getIssue")
    public Result<IssueInfo> getIssue(Integer issueId){
        return  issueBaseInfoService.findIssueById(issueId);
    }
    /*
     * @Description:查询缺陷列表
     * @Author: JMOCOK
     * @param issuePageForm: 分页查询参数
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("查询缺陷列表")
    @PostMapping("/issueList")
    public Result<IssuePage> issueList(@RequestBody IssuePageForm issuePageform){
        return issueBaseInfoService.findIssuePage(issuePageform);
    }
    /*
     * @Description:查询缺陷任务列表
     * @Author: JMOCOK
     * @param issuePageform: 分页查询参数
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("查询缺陷任务列表")
    @PostMapping("/issueTaskList")
    public Result<IssuePage> issueTaskList(@RequestBody IssuePageForm issuePageForm){
        return issueBaseInfoService.findTaskPage(issuePageForm);
    }
    /*
     * @Description:批量删除
     * @Author: JMOCOK
     * @param batchesDeleteIssueForm: 批量删除参数
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("批量删除缺陷")
    @PostMapping("/batchesDelete")
    public Result batchesDelete(@RequestBody @Valid BatchesDeleteIssueForm batchesDeleteIssueForm){
        return issueBaseInfoService.removeByIssueIds(batchesDeleteIssueForm);
    }
    /*
     * @Description:分配任务
     * @Author: JMOCOK
     * @param allotTaskForm: 分配任务参数
     * @return: com.tracesystem.commons.Result
     **/
    @ApiOperation("分配任务")
    @PostMapping("/task")
    public Result task(@RequestBody @Valid AllotTaskForm allotTaskForm){

        return issueBaseInfoService.allotTask(allotTaskForm);
    }

    /*
     * @Description:查询所有父级缺陷
     * @Author: JMOCOK
     * @return: com.tracesystem.commons.Result<com.tracesystem.controller.info.ParentIssueInfo>
     **/
    @ApiOperation("查询所有父级缺陷")
    @GetMapping("/parentIssueList")
    public Result<ParentIssueInfo> parentIssueList(){
        return issueBaseInfoService.findParentIssueList();
    }
    /*
     * @Description:查询缺陷分布情况
     * @Author: JMOCOK
     * @param issueDistributionForm: 查询参数
     * @return: com.tracesystem.commons.Result<com.tracesystem.controller.info.IssueDistributionInfo>
     **/
    @ApiOperation("查询缺陷分布情况")
    @PostMapping("/issueDistribution")
    public Result<IssueDistributionInfo> issueDistribution(@RequestBody IssueDistributionForm issueDistributionForm){
        return issueBaseInfoService.getIssueDistribution(issueDistributionForm);
    }


}

